{extend name="public/layout" /}
{block name="head"}
<style>
  body .ztree-title {
    margin: 8px 0 0;
    font-size: 15px;
    background: #efefef;
    padding: 8px 15px 4px;
    font-weight: 600;
    border: 1px solid #e8e8e8;
  }

  body ul.ztree {
    padding: 0;
    border: 1px solid #e8e8e8;
    border-top: none;
    margin-bottom: 15px;
  }

  body ul.ztree > li {
    background: #fff;
    padding: 8px 8px 8px 25px;
    margin: 0 10px 10px;
    border-bottom: 1px dashed #e8e8e8;
  }

  body ul.ztree > li ul li.level1 {
    background: #f1f1f1;
    padding: 0 5px 0 22px;
    box-sizing: border-box;
    margin: 8px 1%;
    line-height: 31px;
  }

  body ul.ztree > li ul li.level1:after {
    display: block;
    content: '';
    height: 0;
    overflow: hidden;
    clear: both;
  }

  body ul.ztree > li ul:after {
    display: block;
    content: '';
    height: 0;
    overflow: hidden;
    clear: both;
  }

  body ul.ztree > li ul.level1 li {
    line-height: 31px;
  }

  body ul.ztree > li ul li ul li ul li {
    display: inline-block;
    vertical-align: top;
  }

  body ul.ztree li span.button.switch {
    top: 5px;
  }
</style>
{/block}
{block name="body"}

<body>
  <div class="container-fluid p-t-15">
    <div class="card">
      <div class="card-header">
        <h4>修改权限组</h4>
      </div>
      <div class="card-body">
        <form class="form-horizontal" id="form" data-url="/system/auth_group/index.html">
          <div class="form-group">
            <label class="col-sm-2 control-label">名称</label>
            <div class="col-sm-6">
              {:\\helper\\Form::_text('title',$info.title,[
              "datatype"=>"*"
              ])}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">状态</label>
            <div class="col-sm-6">
              {:\\helper\\Form::_radio('status',$info.status,[
              "items-data"=>"D:Dict:getDictByClass:10.13",
              "items-key"=>"dict_code",
              "items-name"=>"dict_value",
              ])}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">权限设置</label>
            <div class="col-sm-10">
              <input type="hidden" name="rules" value="{$info.rules}"/>
              <div class="ztree-title">
                <label><input type="checkbox" class="class-check"/> 全选</label>
              </div>
              <ul id="ztree" class="ztree"></ul>
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-10 col-sm-offset-2">
              <div class="pull-left">
                <button type="button" class="btn btn-primary btn-sub"><i class="mdi mdi-content-save"></i> 保存</button>
                <button type="button" class="btn btn-danger" onclick="helper.closeCurrent()"><i
                    class="mdi mdi-close"></i>
                  关闭
                </button>
              </div>
              <div class="pull-left m-l-15">
                <p class="error-msg"></p>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
  <script>
    var zNodes = JSON.parse('{$rule|raw}');
    //初始化权限列表
    Do('ztree', function () {
      var setting = {
        check: {enable: true},
        view: {showLine: false, showIcon: false, dblClickExpand: false},
        data: {
          simpleData: {enable: true, pIdKey: 'pid', idKey: 'id'},
          key: {name: 'title'}
        }
      };
      $.fn.zTree.init($("#ztree"), setting, zNodes);
      var zTree = $.fn.zTree.getZTreeObj('ztree');
      zTree.setting.check.chkboxType = {"Y": "ps", "N": "ps"};
      //全选
      $('.class-check').click(function () {
        var checked = false;
        if ($(this).prop("checked")) checked = true;
        zTree.checkAllNodes(checked);
      });
      formHelper.init();
      formHelper.subForm({
        beforeCheck: function () { //表单验证前同步编辑器
          var ids = '';
          var treeObj = $.fn.zTree.getZTreeObj('ztree');
          var nodes = treeObj.getCheckedNodes(true);
          if (nodes.length > 0) ids += helper.json2col(nodes, 'id') + ',';
          if (!valid.isEmpty(ids)) ids = ids.substr(0, ids.length - 1);
          $("input[name='rules']").val(ids);
        }
      });
    });
  </script>
</body>
{/block}